
#include "wormnet/WormnetType.h"
#include "wormnet/wm_Exception.h"
#include "wormnet/wm_LibeventChannel.h"
#include "wormnet/wm_RaknetChannel.h"

namespace worm
{

WORM_DLL_EXPORT class wmChannel* ICreateChannelModule(const wmESupportNetType& eNetType, wmConnectedCB pConnectedCB, 
        wmReceiveCB pReceiveCB, wmDisconnectCB pDisconnectCB)
{
    wmChannel* pChannel = NULL;

    switch(eNetType)
    {
    case WM_NET_TYPE_LIBEVENT:
        pChannel = new wmLibeventChannel(pConnectedCB, pReceiveCB, pDisconnectCB);
        break;
    case WM_NET_TYPE_RAKNET:
        pChannel = new wmRaknetChannel(pConnectedCB, pReceiveCB, pDisconnectCB);
        break;
    default:
        throw wmException("ICreateChannelModule: net type (%u) unknow\n", eNetType); 
        return NULL;
    }

    return pChannel;
}

WORM_DLL_EXPORT void IReleaseChannelModule(class wmChannel*& pChannel)
{
    delete pChannel;
    pChannel = NULL;
}

}
